﻿package charts.elements; 
	import charts.elements.PointDotBase;
	import flash.display.BlendMode;
	import flash.display.Graphics;
	import flash.display.Sprite;
	
	class Star extends PointDotBase {
		
		
		
		public function new( index:Float, style:Dynamic ) {
			
			super( index, style );
			
			this.visible = true;
			
			this.graphics.clear();
			this.graphics.lineStyle( style.width, style.colour, 1);// style.alpha );
			var rotation:Int = isNaN(style['rotation']) ? 0 : style['rotation'];
			
			this.drawStar( this.graphics, style['dot-size'], rotation );
			
			var haloSize:Int = style['halo-size']+style['dot-size'];
			var s:Sprite = new Sprite();
			s.graphics.lineStyle( 0, 0, 0 );
			s.graphics.beginFill( 0, 1 );
			this.drawStar(s.graphics, haloSize, rotation );
			s.blendMode = BlendMode.ERASE;
			s.graphics.endFill();
			this.line_mask = s;
			
			this.attach_events();
			
		}
		
		function calcXOnCircle(radius:Float, degrees:Float):Float
		{
			return radius * Math.cos(degrees / 180 * Math.PI);
		}
		
		function calcYOnCircle(radius:Float, degrees:Float):Float
		{
			return radius * Math.sin(degrees / 180 * Math.PI);
		}
		
		function drawStar( graphics:Graphics, radius:Float, rotation:Float ):Void 
		{
			var angle:Int = 360 / 5;

			// Start at top Point (unrotated)
			var degrees:Int = -90 + rotation;
			var i:Int = 0;
			while (i <= 5)
			{
				var x:Int = this.calcXOnCircle(radius, degrees);
				var y:Int = this.calcYOnCircle(radius, degrees);
				
				if (i == 0)
					graphics.moveTo(x, y);
				else
					graphics.lineTo(x, y);
					
				// Move 2 Points clockwise
				degrees += (2 * angle);
				i++;
			}
		}
	}
